package models

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"store/conf"
)

type JsonR struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

var (
	DB  *gorm.DB
	err error
)

func MysqlInit() {
	var Conf = conf.Con.MysqlConfig
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", Conf.User, Conf.Password, Conf.Host, Conf.Port, Conf.Database)
	DB, err = gorm.Open(mysql.Open(dsn))
	if err != nil {
		fmt.Println("连接数据库失败")
		return
	}
	fmt.Println("连接数据库成功")
	DB.AutoMigrate(&Store{}, &User{})
}
